<template>
  <div>
    <top-bar></top-bar>
    <div id="container">
      <div id="content">
        <div id="bg">
          <div id="avatar-con" style="position: relative;width: 80px;height: 80px;overflow: hidden;border-radius: 50%">
            <img id="avatar" :src="$store.getters['user/getUser'].avatar|setAvatar" alt />
            <el-upload
                class="upload-demo"
                :action="baseUrl+'/unit/image'"
                multiple
                name="multipartFile"
                :limit="1"
                :file-list="fileList"
                :auto-upload="true"
                :on-success="success"
                :headers="header">
<!--              <el-button size="small" type="primary">点击上传</el-button>-->
              <div  class="avatar-risk">
                <h3 style="color: white">更换头像</h3>
              </div>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>

          </div>

          <p style="font-size: 24px">{{userName}}</p>

        </div>
        <div id="tab">
          <button @click="tabClick(item.path)" :key="item.id" v-for="item in tabList"  :class="$route.fullPath==`/personal/${item.path}`?'btn active':'btn'">{{item.name}}</button>
        </div>
      </div>
        <transition name="fade">
          <router-view></router-view>
        </transition>


    </div>
  </div>
</template>

<script>
import TopBar from "../../components/content/TopBar";
import {baseUrl} from "@/api/baseUrl";
export default {
  name: "index",
  components: {
    TopBar,
  },
  data() {
    return {
      baseUrl:baseUrl,
      header:{
        token:this.$store.getters["user/getToken"]
      },
      fileList:[],
      userName:this.$store.getters["user/getUser"].userName,
      tabList:[
        {id:1,path:'myArchives',name:'个人信息'},
        {id:2,path:'myDynamic',name:'我的动态'},
        {id:3,path:'myConcern',name:'我的关注'},
        {id:4,path:'myCollection',name:'我的收藏'},
        {id:5,path:'setting',name:'个人设置'},
        {id:6,path:'myFans',name:'关注我的人'}
      ]
    };
  },
  created() {
    console.log(this.$route.fullPath)
  },
  methods: {
    success(res){
      console.log(res)
      this.$message.success(res.msg)
      let imageUrl=res.extend.image
      let user=this.$store.getters["user/getUser"]
      user.avatar=imageUrl
      this.$store.commit("user/SET_USER",user)
      this.fileList=[]
    },
    tabClick(path){
      this.$router.push(path)
    }
  },
};
</script>

<style scoped>
.fade-enter-active {
  transition: all .2s ease;
  transition-delay: .2s;
}

.fade-leave-active {
  transition: all .2s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}

.fade-enter
{
  transform: translateY(30px);
  opacity: 0;
}
.fade-leave-to{
  transform: translateY(-30px);
  opacity: 0;
}
#container {
  width: 100%;
  /*height: 100vh;*/
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #ece0e0;
}
#content {
  box-shadow: 0 2px 4px #e0e0e0;
  margin-top: 20px;
  width: 70%;
  height: 460px;
  background-color: #fff;
}
#bg {
  overflow: hidden;
  width: 100%;
  height: 90%;
  background: url("../../assets/img/pen-4337521_1280.jpg") no-repeat center center;
  background-size: 150% 150%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: rgba(255, 255, 255, 0.8);
  animation: archive 6s linear forwards;
  transform-origin: center center;
}
@keyframes archive {
  0%{
    background-size:150% 150%;
  }
  100%{
    background-size: 100% 100%;
  }
}
#bg * {
  margin: 0;
}
#avatar {
  border-radius: 50%;
  height: 80px;
  width: 80px;
  border: gainsboro solid 2px;
}
#tab {
  width: 100%;
  height: 10%;
  background-color: #fff;
  /*border-bottom: 1px solid blue;*/
  display: flex;
  justify-content: center;
  box-shadow: 0 1px 2px rgb(232, 232, 232);
}
.btn {
  cursor: pointer;
  margin: 0 50px;
  outline: none;
  border: none;
  background-color: #fff;
}
.active {
  font-weight: 600;
  border-bottom: 2px solid orange;
}
.avatar-risk{
  background: rgba(0,0,0,.6);
  position: absolute;
  width:80px;
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  top: 100%;
  transition: all .1s;
  cursor: pointer;
}
#avatar-con:hover .avatar-risk{
  top: 0;
}
</style>
